package middle;

import util.PrintUtils;

public class Solution_48 {
    public void rotate(int[][] matrix) {
        int count = matrix.length / 2, round = 0;
        while (round < count) {
            int length = matrix[round].length;
            int step = length - 2 * round - 1;
            for (int i = 0; i < step; i++) {
                int r = round, c = round + i, preValue, temp;
                preValue = matrix[length - 1 - c][r];

                temp = matrix[r][c];
                matrix[r][c] = preValue;
                preValue = temp;

                temp = matrix[c][length - 1 - r];
                matrix[c][length - 1 - r] = preValue;
                preValue = temp;

                temp = matrix[length - 1 - r][length - 1 - c];
                matrix[length - 1 - r][length - 1 - c] = preValue;
                preValue = temp;

                matrix[length - 1 - c][r] = preValue;
            }
            round++;
        }
    }

    public static void main(String[] args) {
        Solution_48 model = new Solution_48();
//        int[][] ints = {{5,1,9,11},{2,4,8,10},{13,3,6,7},{15,14,12,16}};
        int[][] ints = {{1}};
        for (int[] anInt : ints) {
            PrintUtils.arrayInt(anInt);
        }
        System.out.println();
        model.rotate(ints);
        for (int[] anInt : ints) {
            PrintUtils.arrayInt(anInt);
        }
    }
}
